#include "msgqueue.h"
#include "contact.h"

int main() {
	{
		//创建消息队列
		int res = CreateMsgQ();
		if(res == -1)
		{
			perror("创建消息队列失败\n");
			return -1;
		}
	}
	
	{//用户未注册 
		//输入手机号和密码
		UserType userInfo = {1000, 0, "", "123456"};
		//请求登录
		int res = RequestLogin(&userInfo);
		if(res == 1)
		{
			printf("测试通过！\n");
		}
	}
	
	{
		//构造数据
		UserType userInfo = {1000, 1, "", ""};
		ElementType val;
		val.contactInfo = (ContactType){1000, 13554003465, "张伟", "男", 22,"黄石市青山区长江路1234号"};
		int res = RequestAddContact(&val);//请求添加联系人
		if(res == 0)//判断是否添加成功
		{
			printf("添加成功！\n");
		}
		val.contactInfo = (ContactType){1000, 13900139001, "李娜", "女", 28,"上海市浦东新区张江高科技园区2号"};
		res = RequestAddContact(&val);
		val.contactInfo = (ContactType){1000, 13700137001, "王磊", "男", 45,"广州市天河区体育西路3号"};
		res = RequestAddContact(&val);
		val.contactInfo = (ContactType){1000, 13500135001, "赵敏", "女", 35,"深圳市南山区科技园4号"};
		res = RequestAddContact(&val);
		val.contactInfo = (ContactType){1000, 13600136001, "刘洋", "男", 24,"杭州市西湖区文三路5号"};
		res = RequestAddContact(&val);
		val.contactInfo = (ContactType){1000, 13400134001, "陈思", "女", 42,"成都市武侯区人民南路6号"};
		res = RequestAddContact(&val);
		val.contactInfo = (ContactType){1000, 13300133001, "孙权", "男", 21,"武汉市武昌区中北路9号"};
		res = RequestAddContact(&val);
	}
	

	{
		//构造数据
		PSeqListType pContactList = CreateEpSeqlist();
		if(pContactList == NULL)
		{
			return -1;
		}

		//请求获取联系人
		UserType userInfo = {1000, 0, "", "123456"};
		RequsetGetContactList(&userInfo, pContactList);
		//展示联系人
		printf("展示联系人！\n");
		ShowSeqlist(pContactList, 1);
	}
	
	
	{//注册
		//输入手机号/用户名/密码
		UserType userInfo = {1000, 0, "用户名", "123456"};
		//请求注册
		int res = RequestRegister(&userInfo);
		if(res == 0)
		{
			printf("测试通过！\n");
		}
	}
	
	{//重复登录
		//输入手机号和密码
		UserType userInfo = {1000, 0, "", "123456"};
		//请求登录
		int res = RequestLogin(&userInfo);
		if(res == 2)
		{
			printf("测试通过！\n");
		}
	}

	{//登出
		UserType userInfo = {1000, 1, "用户名", "123456"};
		//请求登出
		int res = RequestLogout(&userInfo);
		if(res == 1)
		{
			printf("测试通过！\n");
		}
	}
	
	{//密码不正确
		//输入手机号和密码
		UserType userInfo = {1000, 0, "", "12345"};
		//请求登录
		int res = RequestLogin(&userInfo);
		if(res == 3)
		{
			printf("测试通过！\n");
		}
	}

	{//登录
		//输入手机号和密码
		UserType userInfo = {1000, 0, "", "123456"};
		//请求登录
		int res = RequestLogin(&userInfo);
		if(res == 0)
		{
			printf("测试通过！\n");
		}
	}

	{//注销
		//输入手机号和密码
		UserType userInfo = {1000, 0, "", "123456"};
		//请求注销
		int res = RequestDestroy(&userInfo);
		if(res == 1)
		{
			printf("测试通过！\n");
		}
	}
	
	{//注销后无法登录
		//输入手机号和密码
		UserType userInfo = {1000, 0, "", "123456"};
		//请求登录
		int res = RequestLogin(&userInfo);
		if(res == 1)
		{
			printf("测试通过！\n");
		}
	}

	{//删除联系人
		//构造数据
		ElementType val = {};
		val.contactInfo = (ContactType){1000, 13600136001, "刘洋", "男", 24,"杭州市西湖区文三路5号"};

		//请求删除
		int res = RequestDeleteContact(&val.contactInfo);
		//判断
		if(res == 0)
		{
			printf("测试通过！\n");
		}
	}

	{//修改联系人
		//构造数据
		ElementType val = {};
		val.contactInfo = (ContactType){1000, 13300133001, "刘洋", "男", 24,"杭州市西湖区文三路5号"};

		//请求修改
		int res = RequestChangeContact(&val.contactInfo);
		//判断
		if(res == 0)
		{
			printf("测试通过！\n");
		}
	}

	{//清空联系人
		UserType userInfo = {1000, 1, "", ""};
		//请求清空
		int res = RequestClearContact(&userInfo);
		//判断
		if(res == 0)
		{
			printf("测试通过！\n");
		}
	}

	{//删除失败
		//构造数据
		ElementType val = {};
		val.contactInfo = (ContactType){1000, 13600136001, "刘洋", "男", 24,"杭州市西湖区文三路5号"};

		//请求删除
		int res = RequestDeleteContact(&val.contactInfo);
		//判断
		if(res == -1)
		{
			printf("测试通过！\n");
		}
	}

	{//修改失败
		//构造数据
		ElementType val = {};
		val.contactInfo = (ContactType){1000, 13300133001, "刘洋", "男", 24,"杭州市西湖区文三路5号"};

		//请求修改
		int res = RequestChangeContact(&val.contactInfo);
		//判断
		if(res == -1)
		{
			printf("测试通过！\n");
		}
	}
    return 0;
}